import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  ParseUUIDPipe,
  Post,
} from '@nestjs/common';
import { CreateAssignRolesToUser, CreateUserDto } from '../dto/user.dto';
import { UsersService } from './users.service';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { UserParam } from 'src/decorator/user.decorator';

@ApiTags('用户')
@Controller('users')
export class UsersController {
  constructor(private readonly service: UsersService) {}

  @Post('addUser')
  @ApiOperation({ summary: '添加用户' })
  async addUser(@Body() dto: CreateUserDto) {
    const data = await this.service.addUser(dto);
    // return {
    //   success: true,
    //   data,
    //   message: '',
    // };
    return data;
  }

  @Get('queryUsers')
  @ApiOperation({ summary: '获取所有用户' })
  async queryUsers() {
    return await this.service.queryUsers();
  }

  @Get('getUserById/:id')
  @ApiOperation({ summary: '获取用户信息' })
  getUserById(@UserParam('id') id: string) {
    console.log('id: ', id);
    return this.service.getUserById(id);
  }
  // @Get('getUserById/:id')
  // @ApiOperation({ summary: '获取用户信息' })
  // async getUserById(@Param('id', new ParseUUIDPipe()) id: string) {
  //   return this.service.getUserById(id);
  // }

  @Delete('deleteUserById/:id')
  @ApiOperation({ summary: '删除用户' })
  async deleteUserById(@Param('id') id: string) {
    return this.service.deleteUserById(id);
  }

  @Post('assignRolesToUser')
  @ApiOperation({ summary: '用户添加单个或多个角色' })
  async assignRolesToUser(@Body() dto: CreateAssignRolesToUser) {
    return this.service.assignRolesToUser(dto.userId, dto.rolesIds);
  }
}
